<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Gmail,Flask,AWS,API," />





  <link rel="alternate" href="/atom.xml" title="Kingname" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="故事背景2014年12月28号开始，Gmail被伟大的墙从协议上封禁，POP3、SMTP、IAMP全部阵亡。于是不仅网页不能打开Gmail，连邮件客服端都不能使用Gmail收发邮件了。
Gmail在国内的用户相当的广泛，难道就真的不用了吗？当然不是。虽然使用VPN可以翻出长城，但是开着VPN做其他事情又不太方便。于是，一种Gmail的转发服务变得重要起来。
这篇文章将详细介绍如何使用亚马逊云AWS">
<meta property="og:type" content="article">
<meta property="og:title" content="使用AWS亚马逊云搭建Gmail转发服务（一）">
<meta property="og:url" content="https://kingname.info/2014/12/30/使用AWS亚马逊云搭建Gmail转发服务/index.html">
<meta property="og:site_name" content="Kingname">
<meta property="og:description" content="故事背景2014年12月28号开始，Gmail被伟大的墙从协议上封禁，POP3、SMTP、IAMP全部阵亡。于是不仅网页不能打开Gmail，连邮件客服端都不能使用Gmail收发邮件了。
Gmail在国内的用户相当的广泛，难道就真的不用了吗？当然不是。虽然使用VPN可以翻出长城，但是开着VPN做其他事情又不太方便。于是，一种Gmail的转发服务变得重要起来。
这篇文章将详细介绍如何使用亚马逊云AWS">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/1.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/开启gmailapi.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/openapi.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/凭证.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/id.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/oau.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/sigin.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/sign2.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/sign3.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/listget.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/data1.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/data2.jpg">
<meta property="og:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/show.jpg">
<meta property="og:updated_time" content="2016-11-30T13:56:50.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用AWS亚马逊云搭建Gmail转发服务（一）">
<meta name="twitter:description" content="故事背景2014年12月28号开始，Gmail被伟大的墙从协议上封禁，POP3、SMTP、IAMP全部阵亡。于是不仅网页不能打开Gmail，连邮件客服端都不能使用Gmail收发邮件了。
Gmail在国内的用户相当的广泛，难道就真的不用了吗？当然不是。虽然使用VPN可以翻出长城，但是开着VPN做其他事情又不太方便。于是，一种Gmail的转发服务变得重要起来。
这篇文章将详细介绍如何使用亚马逊云AWS">
<meta name="twitter:image" content="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/1.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://kingname.info/2014/12/30/使用AWS亚马逊云搭建Gmail转发服务/"/>





  <title> 使用AWS亚马逊云搭建Gmail转发服务（一） | Kingname </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Kingname</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">给时光以生命。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tweet">
          <a href="/tweet" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-twitter"></i> <br />
            
            时间
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="https://kingname.info/2014/12/30/使用AWS亚马逊云搭建Gmail转发服务/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="Kingname">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.png">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Kingname">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Kingname" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                使用AWS亚马逊云搭建Gmail转发服务（一）
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2014-12-30T15:41:35+08:00">
                2014-12-30
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Python/" itemprop="url" rel="index">
                    <span itemprop="name">Python</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <a href="/2014/12/30/使用AWS亚马逊云搭建Gmail转发服务/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2014/12/30/使用AWS亚马逊云搭建Gmail转发服务/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="故事背景"><a href="#故事背景" class="headerlink" title="故事背景"></a>故事背景</h2><p>2014年12月28号开始，Gmail被伟大的墙从协议上封禁，POP3、SMTP、IAMP全部阵亡。于是不仅网页不能打开Gmail，连邮件客服端都不能使用Gmail收发邮件了。</p>
<p>Gmail在国内的用户相当的广泛，难道就真的不用了吗？当然不是。虽然使用VPN可以翻出长城，但是开着VPN做其他事情又不太方便。于是，一种Gmail的转发服务变得重要起来。</p>
<p>这篇文章将详细介绍如何使用亚马逊云AWS的免费主机EC2，配合Gmail的API来编写一个Gmail的转发程序。程序在设定时间内访问Gmail收件箱，发现新邮件以后，就通过另一个邮箱转发到国内邮箱中。每一次转发记录到一个日志文件中，并使用Flask搭建网站来，从而直观的检查接收发送记录。</p>
<p>AWS的免费主机EC2的申请不是本文的重点，网上有很多教程，故略去不讲。<br>Flask环境的搭建不是本文重点，网上有很多教程，故略去不讲。</p>
<p>本篇先讲解Gmail API的使用，下一篇讲解如何制作转发程序。</p>
<h2 id="授权之路"><a href="#授权之路" class="headerlink" title="授权之路"></a>授权之路</h2><p>既然要是用Gmail的API，那就要开通Gmail的授权。Google的官方英文教程请戳-&gt;<a href="https://developers.google.com/gmail/api/quickstart/quickstart-python" target="_blank" rel="external">Run a Gmail App in Python</a></p>
<h3 id="打开Gmail-API"><a href="#打开Gmail-API" class="headerlink" title="打开Gmail API"></a>打开Gmail API</h3><p>访问<a href="https://console.developers.google.com/project" target="_blank" rel="external">https://console.developers.google.com/project</a>，单击“建立档案”选项，新建一个项目。我这里新建的项目叫做“gmail”，如下图：</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/1.jpg" alt=""></p>
<p>单击新建的档案“gmail”，在左侧点击“API和验证”，选择“API”，然后再右侧中间搜索框中输入Gmail，找到后打开。如下图：</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/开启gmailapi.jpg" alt=""></p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/openapi.jpg" alt=""></p>
<p>然后点击左侧“凭证”，选择“建立新的用户端ID”</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/凭证.jpg" alt=""></p>
<p>这个时候注意一定要选择第三项，才能正确生成json文件。选择第三项，并填写完一些信息后，做如下选择，并点击“建立用户端ID”</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/id.jpg" alt=""></p>
<p>接下来，下载json文件。</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/oau.jpg" alt=""></p>
<h3 id="验证机器"><a href="#验证机器" class="headerlink" title="验证机器"></a>验证机器</h3><p>在服务器上新建ghelper文件夹：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mkdir ghelper</div><div class="line">cd ghelper</div></pre></td></tr></table></figure></p>
<p>然后安装Google API Python Client库。建议使用pip安装而不是easy_install，因为pip安装的库文件可以卸载，而easy_install安装的库文件不能卸载。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo pip install --upgrade google-api-python-client</div></pre></td></tr></table></figure></p>
<p>为了使代码中的run.tools()能够正常执行，还需要安装gflags:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo pip install python-gflags</div></pre></td></tr></table></figure></p>
<p>将json文件上传到AWS服务器上，我放在了~/wwwproject/ghelper目录下面,并且重命名为client_secret.json,这样代码就不需要进行修改了。同时在本目录下面新建ghelper_api.py文件，文件内容为官方指南中的验证机器的代码，如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div></pre></td><td class="code"><pre><div class="line">import httplib2</div><div class="line"></div><div class="line">from apiclient.discovery import build</div><div class="line">from oauth2client.client import flow_from_clientsecrets</div><div class="line">from oauth2client.file import Storage</div><div class="line">from oauth2client.tools import run</div><div class="line"></div><div class="line"># Path to the client_secret.json file downloaded from the Developer Console</div><div class="line">CLIENT_SECRET_FILE = &apos;client_secret.json&apos;</div><div class="line"></div><div class="line"># Check https://developers.google.com/gmail/api/auth/scopes for all available scopes</div><div class="line">OAUTH_SCOPE = &apos;https://www.googleapis.com/auth/gmail.readonly&apos;</div><div class="line"></div><div class="line"># Location of the credentials storage file</div><div class="line">STORAGE = Storage(&apos;gmail.storage&apos;)</div><div class="line"></div><div class="line"># Start the OAuth flow to retrieve credentials</div><div class="line">flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)</div><div class="line">http = httplib2.Http()</div><div class="line"></div><div class="line"># Try to retrieve credentials from storage or run the flow to generate them</div><div class="line">credentials = STORAGE.get()</div><div class="line">if credentials is None or credentials.invalid:</div><div class="line">  credentials = run(flow, STORAGE, http=http)</div><div class="line"></div><div class="line"># Authorize the httplib2.Http object with our credentials</div><div class="line">http = credentials.authorize(http)</div><div class="line"></div><div class="line"># Build the Gmail service from discovery</div><div class="line">gmail_service = build(&apos;gmail&apos;, &apos;v1&apos;, http=http)</div><div class="line"></div><div class="line"># Retrieve a page of threads</div><div class="line">threads = gmail_service.users().threads().list(userId=&apos;me&apos;).execute()</div><div class="line"></div><div class="line"># Print ID for each thread</div><div class="line">if threads[&apos;threads&apos;]:</div><div class="line">  for thread in threads[&apos;threads&apos;]:</div><div class="line">    print &apos;Thread ID: %s&apos; % (thread[&apos;id&apos;])</div></pre></td></tr></table></figure></p>
<p>运行ghelper_api.py，进入Google验证阶段。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">python ghelper_api.py</div></pre></td></tr></table></figure></p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/sigin.jpg" alt=""></p>
<p>在红线处按回车键就可以进入输入模式。输入gmail和密码以后，移动光标到“Sign in”回车，然后进入如下页面：</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/sign2.jpg" alt=""></p>
<p>输入你的信息，验证通过以后会让你进入开启浏览器的javascript功能。可是Linux服务器哪来的浏览器？这个时候按键盘的Ctrl + Z来取消。</p>
<p>继续输入：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">python ghelper_api.py --noauth_local_webserver</div></pre></td></tr></table></figure></p>
<p>会提示离线验证，如果仍然失败的话，就继续Ctrl+Z然后再输入上面的代码，很快就会让你离线验证：</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/sign3.jpg" alt=""></p>
<p>复制他给出的网址，并在自己电脑上登录后，复制他给出的代码并粘贴回服务器上。验证通过。</p>
<h3 id="使用API"><a href="#使用API" class="headerlink" title="使用API"></a>使用API</h3><p>打开<a href="https://developers.google.com/gmail/api/v1/reference/" target="_blank" rel="external">API Reference</a>，查看Gmail API的用法。</p>
<p>这里用Users.messages的list和get方法来演示API的使用。</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/listget.jpg" alt=""></p>
<p>先查看list的说明:</p>
<blockquote>
<p>Lists the messages in the user’s mailbox.</p>
</blockquote>
<p>列出邮箱里的信息。这里实际上列出来的是每一封邮件的id,于是，使用这个id，通过get就能获得邮件的内容。</p>
<p>通过查看list和get的使用范例：</p>
<p>list:<br><a href="https://developers.google.com/gmail/api/v1/reference/users/messages/list" target="_blank" rel="external">https://developers.google.com/gmail/api/v1/reference/users/messages/list</a><br>get:<br><a href="https://developers.google.com/gmail/api/v1/reference/users/messages/get" target="_blank" rel="external">https://developers.google.com/gmail/api/v1/reference/users/messages/get</a></p>
<p>构造出以下的完整代码：</p>
<pre><code>#-*-coding:utf-8 -*-
import httplib2

from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run
from apiclient import errors
import base64
import email


# Path to the client_secret.json file downloaded from the Developer Console
CLIENT_SECRET_FILE = &apos;client_secret.json&apos;

# Check https://developers.google.com/gmail/api/auth/scopes for all available scopes
OAUTH_SCOPE = &apos;https://www.googleapis.com/auth/gmail.readonly&apos;

# Location of the credentials storage file
STORAGE = Storage(&apos;gmail.storage&apos;)

# Start the OAuth flow to retrieve credentials
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()

# Try to retrieve credentials from storage or run the flow to generate them
credentials = STORAGE.get()
if credentials is None or credentials.invalid:
  credentials = run(flow, STORAGE, http=http)

# Authorize the httplib2.Http object with our credentials
http = credentials.authorize(http)

# Build the Gmail service from discovery
gmail_service = build(&apos;gmail&apos;, &apos;v1&apos;, http=http)

# Retrieve a page of threads
# threads = gmail_service.users().threads().list(userId=&apos;me&apos;).execute()

# # Print ID for each thread
# if threads[&apos;threads&apos;]:
#   for thread in threads[&apos;threads&apos;]:
#     print &apos;Thread ID: %s&apos; % (thread[&apos;id&apos;])

def ListMessagesWithLabels(service, user_id, label_ids=[]):
  &quot;&quot;&quot;List all Messages of the user&apos;s mailbox with label_ids applied.

  Args:
    service: Authorized Gmail API service instance.
    user_id: User&apos;s email address. The special value &quot;me&quot;
    can be used to indicate the authenticated user.
    label_ids: Only return Messages with these labelIds applied.

  Returns:
    List of Messages that have all required Labels applied. Note that the
    returned list contains Message IDs, you must use get with the
    appropriate id to get the details of a Message.
  &quot;&quot;&quot;
  try:
    response = service.users().messages().list(userId=user_id,
                                               labelIds=label_ids).execute()
    messages = []
    if &apos;messages&apos; in response:
      messages.extend(response[&apos;messages&apos;])

    while &apos;nextPageToken&apos; in response:
      page_token = response[&apos;nextPageToken&apos;]
      response = service.users().messages().list(userId=user_id,
                                                 labelIds=label_ids,
                                                 pageToken=page_token).execute()
      messages.extend(response[&apos;messages&apos;])

    return messages
  except errors.HttpError, error:
    print &apos;An error occurred: %s&apos; % error

def GetMessage(service, user_id, msg_id):
  &quot;&quot;&quot;Get a Message with given ID.

  Args:
    service: Authorized Gmail API service instance.
    user_id: User&apos;s email address. The special value &quot;me&quot;
    can be used to indicate the authenticated user.
    msg_id: The ID of the Message required.

  Returns:
    A Message.
  &quot;&quot;&quot;
  try:
    message = service.users().messages().get(userId=user_id, id=msg_id).execute()

    print &apos;Message snippet: %s&apos; % message[&apos;snippet&apos;]

    return message
  except errors.HttpError, error:
    print &apos;An error occurred: %s&apos; % error

a = ListMessagesWithLabels(gmail_service,&apos;me&apos;)[0][&apos;id&apos;]
b = GetMessage(gmail_service,&apos;me&apos;,a)
print b[&apos;snippet&apos;]
print b[&apos;payload&apos;][&apos;headers&apos;][3][&apos;value&apos;]
</code></pre><p>通过观察GetMessage返回的数据，可以看到，返回的是一个字典dict,邮件的内容在key为snippet的里面。发件人在[‘payload’][‘headers’][3][‘value’]里面，如图：<br><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/data1.jpg" alt=""><br><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/data2.jpg" alt=""></p>
<p>代码在服务器上运行效果如图：</p>
<p><img src="http://7sbpmp.com1.z0.glb.clouddn.com/gmail/show.jpg" alt=""></p>
<p>至此，Gmail API在AWS服务器上的部署完成。下一篇文章将会介绍如何使用Python轮询Gmail的收件箱，并在有新邮件的时候转发到国内邮箱。</p>

      
    </div>

    <div>
      
        
<div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/wechatplatform.jpg" alt="Kingname wechat" style="width: 200px; max-width: 100%;"/>
    <div>第一时间获取最新文章更新，请订阅我的微信公众号：未闻Code</div>
</div>


      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Gmail/" rel="tag"># Gmail</a>
          
            <a href="/tags/Flask/" rel="tag"># Flask</a>
          
            <a href="/tags/AWS/" rel="tag"># AWS</a>
          
            <a href="/tags/API/" rel="tag"># API</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2014/12/29/对一个罗马数字与阿拉伯数字转换算法的分析/" rel="next" title="对一个罗马数字与阿拉伯数字转换算法的分析">
                <i class="fa fa-chevron-left"></i> 对一个罗马数字与阿拉伯数字转换算法的分析
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2014/12/31/使用亚马逊云AWS搭建Gmail邮件转发服务二/" rel="prev" title="使用AWS亚马逊云搭建Gmail转发服务（二）">
                使用AWS亚马逊云搭建Gmail转发服务（二） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="Kingname" />
          <p class="site-author-name" itemprop="name">Kingname</p>
          <p class="site-description motion-element" itemprop="description">爬虫工程师，极客学院讲师，Python, Scrapy, MongoDB, Redis, Pandas, Golang。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">42</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">66</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/kingname" target="_blank" title="Github">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  Github
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="mailto:contact@kingname.info" target="_blank" title="Mail">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  Mail
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://chuangzaoshi.com/" title="创造狮" target="_blank">创造狮</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#故事背景"><span class="nav-number">1.</span> <span class="nav-text">故事背景</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#授权之路"><span class="nav-number">2.</span> <span class="nav-text">授权之路</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#打开Gmail-API"><span class="nav-number">2.1.</span> <span class="nav-text">打开Gmail API</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#验证机器"><span class="nav-number">2.2.</span> <span class="nav-text">验证机器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用API"><span class="nav-number">2.3.</span> <span class="nav-text">使用API</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Kingname</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  





  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

  


</body>
</html>
